package com.ncmmall.api.apis.mall.wechat;


import com.ncmmall.application.util.HttpRequests;
import com.feijin.commons.exceptions.InterfaceException;
import com.feijin.commons.lang.ArithUtils;
import com.feijin.commons.lang.MD5s;
import com.feijin.commons.lang.PropertiesHelps;
import com.feijin.commons.lang.Randoms;
import com.feijin.commons.xml.Xmls;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 90
 */
@Slf4j
class WechatPay {

    /**
     * 拼团订单支付
     */
    WechatPayOrderResponse wechatGroupBookingPayOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_groupbooking_order");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);

        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }


    /**
     * 预售订单定金支付
     *
     * @param outTradeNo
     * @param amount
     * @param body
     * @param openid
     * @return
     */
    WechatPayOrderResponse presellSubscriptionPayOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_presell_subscription_order");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);


        order.setSign(buildMpRequestSign(order, key));


        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }

    /**
     * 预售订单尾款支付
     *
     * @param outTradeNo
     * @param amount
     * @param body
     * @param openid
     * @return
     */
    WechatPayOrderResponse presellRetainagePayOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_presell_retainage_order");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);


        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }

    /**
     * 小程序支付
     *
     * @param outTradeNo 订单号
     * @param amount     支付金额
     * @return
     */
    WechatPayOrderResponse mpOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_order");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);


        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }

    /**
     * 购物卡订单
     *
     * @param outTradeNo 订单号
     * @param amount     支付金额
     * @return
     */
    WechatPayOrderResponse shoppingCardOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_shoppingcard");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);


        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }


    /**
     * 小程序支付
     *
     * @param outTradeNo 订单号
     * @param amount     支付金额
     * @return
     */
    WechatPayOrderResponse courseOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_course");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);


        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }


    /**
     * 小程序支付
     *
     * @param outTradeNo 订单号
     * @param amount     支付金额
     * @return
     */
    WechatPayOrderResponse vipOrder(String outTradeNo, double amount, String body, String openid) {

        //公众平台开发者appid
        String appid = PropertiesHelps.getValue("wx.appid");

        //商户平台商户id
        String mchId = PropertiesHelps.getValue("wx.mch_id");

        //微信的随机字符串
        String nonce = Randoms.getRandomCharAndNumr(32);

        //异步通知回调地址
        String notifyurl = PropertiesHelps.getValue("wx.notify_url_vip");

        //服务ip地址
        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");

        //订单金额单位分
        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));

        // JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
        String tradeType = "JSAPI";
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        //        order.setOpenid(openid);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        order.setNotify_url(notifyurl);
        order.setTrade_type(tradeType);
        order.setSpbill_create_ip(clientIp);

        //服务商支付
        order.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        order.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));
        order.setSub_openid(openid);

        order.setSign(buildMpRequestSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        return response;
    }


    /**
     * 微信小程序支付统一下单签名
     *
     * @param order
     * @return
     */
    private String buildMpRequestSign(WechatPayOrder order, String key) {
        //        String sign = "appid=" + order.getAppid() + "&body=" + order.getBody() + "&mch_id=" + order.getMch_id() + "&nonce_str=" + order.getNonce_str() + "&notify_url=" + order.getNotify_url() + "&openid=" + order.getOpenid() + "&out_trade_no=" + order.getOut_trade_no() + "&spbill_create_ip=" + order.getSpbill_create_ip() + "&sub_appid=" + order.getSub_appid() + "&sub_mch_id=" + order.getSub_mch_id() + "&sub_openid=" + order.getSub_openid() + "&total_fee=" + order.getTotal_fee() + "&trade_type=" + order.getTrade_type() + "&key=" + key;
        String sign = "appid=" + order.getAppid() + "&body=" + order.getBody() + "&mch_id=" + order.getMch_id() + "&nonce_str=" + order.getNonce_str() + "&notify_url=" + order.getNotify_url() + "&out_trade_no=" + order.getOut_trade_no() + "&spbill_create_ip=" + order.getSpbill_create_ip() + "&sub_appid=" + order.getSub_appid() + "&sub_mch_id=" + order.getSub_mch_id() + "&sub_openid=" + order.getSub_openid() + "&total_fee=" + order.getTotal_fee() + "&trade_type=" + order.getTrade_type() + "&key=" + key;

        //        appid=wx245ae20cfad7c0f0&body=拖拖部落电商订单支付&mch_id=1534603651&nonce_str=u01tt9p51780uc7pb6334qr3un245ur8&notify_url=http://tuotuo.51feijin.com/api/wechat/pay/order/callback&out_trade_no=202006101730350213186800&spbill_create_ip=120.79.0.21&sub_appid=wx98a6b9c99c3b5734&sub_mch_id=1592985701&sub_openid=obbEZ0WrdcVI5J08S0CLbO2HoYZ0&total_fee=2&trade_type=JSAPI
        //        appid=wx245ae20cfad7c0f0&body=拖拖部落电商订单支付&mch_id=1534603651&nonce_str=u01tt9p51780uc7pb6334qr3un245ur8&notify_url=http://tuotuo.51feijin.com/api/wechat/pay/order/callback&out_trade_no=202006101730350213186800&spbill_create_ip=120.79.0.21&sub_appid=wx98a6b9c99c3b5734&sub_mch_id=1592985701&sub_openid=obbEZ0WrdcVI5J08S0CLbO2HoYZ0&total_fee=2&trade_type=JSAPI&key=i2dvGOIrd2ICvepytjjExUFSSrL3GUy0


        log.info("[微信小程序支付统一下单参数拼接签名:]" + sign);
        String result = MD5s.execute(sign).toUpperCase();
        log.info("[微信小程序支付统一下单签名:]" + result);
        return result;
    }

    /**
     * 查询订单状态
     *
     * @param outTradeNo 订单号
     */
    String orderQuery(String outTradeNo) {


        //微信的随机字符串,没卵用
        String nonce = Randoms.getRandomCharAndNumr(32);
        String appid = PropertiesHelps.getValue("wx.appid");
        String mchId = PropertiesHelps.getValue("wx.mch_id");
        String key = PropertiesHelps.getValue("wx.key");

        //查询url
        String url = "https://api.mch.weixin.qq.com/pay/orderquery";

        WechatQueryRequestDTO wechatQueryRequestDTO = new WechatQueryRequestDTO();
        wechatQueryRequestDTO.setAppid(appid);
        wechatQueryRequestDTO.setMch_id(mchId);
        wechatQueryRequestDTO.setNonce_str(nonce);
        wechatQueryRequestDTO.setOut_trade_no(outTradeNo);

        wechatQueryRequestDTO.setSub_appid(PropertiesHelps.getValue("wx.sub_appid"));
        wechatQueryRequestDTO.setSub_mch_id(PropertiesHelps.getValue("wx.sub_mch_id"));

        wechatQueryRequestDTO.setSign(buildMpRequestSign(wechatQueryRequestDTO, key));

        String xml = Xmls.convertToXml(wechatQueryRequestDTO, false);
        log.info("[xml]" + xml);

        WechatQueryOrderResponseDTO response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatQueryOrderResponseDTO.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }

        if ("SUCCESS".equals(response.getTrade_state())) {
            return "SUCCESS";
        }

        return "FAIL";
    }


    /**
     * 微信查询订单签名
     *
     * @param order
     * @param key
     * @return
     */
    private String buildMpRequestSign(WechatQueryRequestDTO order, String key) {
//        String sign = "appid=" + order.getAppid() + "&mch_id=" + order.getMch_id() + "&nonce_str=" + order.getNonce_str() + "&out_trade_no=" + order.getOut_trade_no() + "&key=" + key;


        String sign = "appid=" + order.getAppid() + "&mch_id=" + order.getMch_id() + "&nonce_str=" + order.getNonce_str() + "&out_trade_no=" + order.getOut_trade_no() + "&sub_appid=" + order.getSub_appid() + "&sub_mch_id=" + order.getSub_mch_id() + "&key=" + key;


        log.info("[微信支付查询订单参数拼接签名:]" + sign);
        String result = MD5s.execute(sign).toUpperCase();
        log.info("[微信支付查询订单签名:]" + result);
        return result;
    }

    /**
     * 扫码支付
     *
     * @return
     */
    public WechatPayOrderResponse scanCode(String code, String outTradeNo, String body, double amount) {

        String appid = PropertiesHelps.getValue("wx.appid");//公众平台开发者appid
        String mchId = PropertiesHelps.getValue("wx.mch_id");//商户平台商户id
        String nonce = Randoms.getRandomCharAndNumr(32);//微信的随机字符串

        String clientIp = PropertiesHelps.getValue("wx.spbill_create_ip");//服务ip地址

        int totalFee = ArithUtils.roundHalfUp(ArithUtils.mul(amount, 100));//订单金额单位分
        String key = PropertiesHelps.getValue("wx.key");

        WechatPayOrder order = new WechatPayOrder();
        //appid、mch_id、nonce_str、sign、body、out_trade_no、total_fee、spbill_create_ip、auth_code
        order.setAppid(appid);
        order.setMch_id(mchId);
        order.setNonce_str(nonce);
        order.setBody(body);
        order.setOut_trade_no(outTradeNo);
        order.setTotal_fee(String.valueOf(totalFee));
        //        order.setLimit_pay("no_credit");//指定不能使用信用卡支付
        order.setAuth_code(code);
        order.setSpbill_create_ip(clientIp);
        order.setSign(buildScanSign(order, key));

        String xml = Xmls.convertToXml(order, false);
        log.info("[xml]" + xml);

        String url = "https://api.mch.weixin.qq.com/pay/micropay";
        WechatPayOrderResponse response = Xmls.converyToObject(HttpRequests.postEntity(url, xml, "application/xml"), WechatPayOrderResponse.class);

        if ("FAIL".equals(response.getReturn_code())) {
            throw new InterfaceException(response.getReturn_msg());
        }

        if ("FAIL".equals(response.getResult_code())) {
            throw new InterfaceException(response.getErr_code_des());
        }
        //        log.info("[微信支付查询订单签名:]" + response.);
        return response;
    }

    /**
     * 微信扫码签名
     *
     * @param order
     * @return
     */
    private String buildScanSign(WechatPayOrder order, String key) {
        String sign = "appid=" + order.getAppid() + "&auth_code=" + order.getAuth_code() + "&body=" + order.getBody() + "&mch_id=" + order.getMch_id() + "&nonce_str=" + order.getNonce_str() //+ "&notify_url=" + order.getNotify_url()
                //                + "&openid=" + order.getOpenid()
                + "&out_trade_no=" + order.getOut_trade_no() + "&spbill_create_ip=" + order.getSpbill_create_ip() + "&total_fee=" + order.getTotal_fee()
                //                + "&trade_type=" + order.getTrade_type()
                + "&key=" + key;
        log.info("[微信小程序支付统一下单参数拼接签名:]" + sign);
        String result = MD5s.execute(sign).toUpperCase();
        log.info("[微信小程序支付统一下单签名:]" + result);
        return result;
    }
}
